Visualizing `yield` and `yield*` in generator functions.
The **`yield`** operator pauses a generator function's execution and returns the value of the expression following it. The generator's state is saved, and it resumes from the same point when its `next()` method is called.
function* simpleGenerator() { yield 1; yield 2; yield 3; }
Current Generator State:
Returned Values:
The **`yield*`** operator is used to delegate to another generator function or iterable object. It iterates over the delegated generator/iterable and yields each of its values. It effectively flattens a nested generator.
function* innerGenerator() { yield 'A'; yield 'B'; } function* outerGenerator() { yield 1; yield* innerGenerator(); yield 2; }
Current Generator State:
Returned Values: